<template>
    <div class="padding20">
        <el-form :rules="mRules" :model="mFormData" ref="mFormData" label-width="180px"
                 style="margin-left: 30px;margin-right: 60px;">
            <el-form-item label="用户名" prop="name">
                <el-input v-model="mFormData.name" maxlength="50" placeholder="用户名"/>
            </el-form-item>
            <el-form-item label="电话" prop="phone">
                <el-input v-model="mFormData.phone" maxlength="11" placeholder="电话"/>
            </el-form-item>
            <el-form-item label="角色" prop="roleId">
                <el-select placeholder="请选择" v-model="mFormData.roleId"
                           class="mi-item w200" clearable>
                    <el-option label="政府部门" value="11"/>
                    <el-option label="企事业单位" value="12"/>
                    <el-option label="个人用户" value="13"/>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button @click="back(beforeUrl)" size="medium">返 回</el-button>
                <el-button type="primary" plain @click="startUpdate()" size="medium">确 定</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script lang="ts">
    import {Component} from 'vue-property-decorator'
    import {API} from "@/aconst/API";
    import {ElForm} from "element-ui/types/form";
    import {mixins} from "vue-class-component";
    import BaseVue from "@/core/mixin/BaseVue";
    import {errorMsg, successMsg} from "@/core/utils/message";
    import $http from "@/core/utils/http";
    import {rule} from "@/core/utils/rule";
    import Kit from "@/core/mixin/Kit";

    @Component({
        name: 'UserEdit',
        components: {},
    })
    export default class UserEdit extends mixins(BaseVue, Kit) {
        mFormData: any = {};
        mRules = {
            name: [rule.notNullBlur()],
        };

        async mounted() {
            this.getInfo();
        }

        //重新获取焦点
        activated() {
            this.getInfo();
        }

        //失去焦点
        deactivated() {
        }


        getInfo() {
            console.log(this.beforeName);
            console.log(this.beforeUrl);
            $http.post(API.sysUserInfo, {id: this.$route.params.id})
                .then((res: any) => {
                    if (res.success) {
                        successMsg("操作成功");
                    }
                });
        }

        //执行修改操作
        insert() {
            (this.$refs.mFormData as ElForm).validate((valid: boolean) => {
                if (valid) {
                    $http.post(API.adminAppUserUpdate, this.mFormData)
                        .then((res: any) => {
                            if (res.success) {
                                successMsg("操作成功");
                            }
                        });
                } else {
                    errorMsg("表单内容填写错误，请检查！")
                }
            });
        }

        //文件上传地址
        uploadUrl = API.adminUploadUrl;
    }


</script>
<style lang="scss">

</style>
